package br.gov.cemaden.cliente.precipitacao.repository;

import java.lang.reflect.InvocationTargetException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author alan.oliveira
 * @param <T>
 */
public class RepositoryFactory<T> {
    
    EntityManager em;
    private T o;
    
    
    public RepositoryFactory(Class object) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("cliente-cemaden");
        if(!em.isOpen())
            this.em = emf.createEntityManager();
        
        this.o = (T) object.getDeclaredConstructor(EntityManager.class).newInstance(this.em);
    }        
    
    public T get(){
        return this.o;
    } 
   
}
